<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. -->
<!DOCTYPE html>
<html>

<head>
    <!-- Office JavaScript API -->
    <script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
</head>

<body>
    <p>This add-in will insert the text 'Hello world!'.</p>
    <button id="helloButton">Say hello</button>

    <!-- The following image URL tracks diagnostic data for this sample add-in. Please remove the image tag if you reuse this sample in your own code project. -->
    <img src="https://pnptelemetry.azurewebsites.net/pnp-officeaddins/samples/word-add-in-hello-world-run" />
</body>

<script>
    Office.onReady((info) => {
        // Check that we loaded into Word
        if (info.host === Office.HostType.Word) {
            document.getElementById("helloButton").onclick = sayHello;
        }
    });

    function sayHello() {
        return Word.run((context) => {

            // insert a paragraph at the start of the document.
            const paragraph = context.document.body.insertParagraph("Hello World", Word.InsertLocation.start);
            
            // sync the context to run the previous API call, and return.
            return context.sync();
        });
    }
</script>

</html>